package com.shushan.web;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.shushan.ui.CustomDialog;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

/**
 * @ClassName: SetGuideWebActivity
 * @Desciption: 设置引导webview
 * @author: yichaohua
 * @date: 2018-05-10
 */
public class SetGuideWebActivity extends BaseWebActivity{

    private static final String TAG = "SetGuideWebActivity";

    private static final String FINISH_URL = "shushanbao://127.0.0.1/setcomplete";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mWebView.setWebViewClient(mWebViewClient);
    }

    WebViewClient mWebViewClient = new WebViewClient(){

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if(url.contains(FINISH_URL)){
                onBackAction(100);
            }else {
                view.loadUrl(url);
            }
            return true;
        }

    };

    @Override
    protected void onLeftBackward() {
        showNoBackWarnDialog();
    }

    private void showNoBackWarnDialog() {
        new CustomDialog.Builder(this)
                .setTitle("温馨提示")
                .setMessage("您尚未完成设置，将会影响您的使用，是否退出？")
                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                        onBackAction(100);
                    }
                })
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create().show();
    }
}
